import React, { Suspense } from "react";
import { Switch, Route, Redirect } from "react-router-dom";

const RouterView = (props) => {
	const { routes } = props
	return (
		<Suspense>
			<Switch>
				{routes.map((route) => {
					let { redirect, path, name, from, to, exact, meta, component, children } = route
					let config = {}
					if (redirect) {
						return <Redirect key={path} from={from} to={to} exact={exact} />
					}
					config = { path }
					if (exact) config.exact = true
					return <Route key={path} {...config} component={component} />
				})}
			</Switch>
		</Suspense>
	)
}

export default RouterView